const fp = require('lodash/fp');

let cars = [{name:'Farr FF',dollar_value:70000, in_stock:true},{name:'Spark C12 Zagato',dollar_value:13200,in_stock:true},{name:'Audi R8',dollar_value:64800,in_stock:false}];

let _average = function(xs){
  return fp.reduce(fp.add, 0 ,xs) / xs.length
}

let _underscore = fp.replace(/\W+/g,'_');

const f1 = fp.flowRight(fp.props('in_stock'), fp.last) //1.获取最后一个car的in_stock

const f2 = fp.flowRight(fp.props('name'), fp.first) //2.获取第一个car的name

const f3 = fp.flowRight(_average,fp.map(item => fp.props('dollar_value',item))) //3.获取车报价的平均值

const f4 = fp.flowRight(fp.toLower, _underscore, fp.props('name'))  //4.name字符串转化
const sanitizeNames = fp.map(f4)


console.log(f1(cars))
console.log(f2(cars))
console.log(f3(cars))
console.log(sanitizeNames(cars))